package com.kimoge.spring6.resources.resource;

import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author kimoge
 * @date 2025/8/30
 * @description 测试ClassPathResource
 */
public class ClassPathResourceDemo {

    public static void main(String[] args) {
        String classPath = "properties1.txt";
        loadResource(classPath);
    }

    public static void loadResource(String path) {
        ClassPathResource classPathResource = new ClassPathResource(path);
        System.out.println(classPathResource.getPath());
        System.out.println(classPathResource.getFilename());
        System.out.println(classPathResource.getDescription());

        try {
            InputStream inputStream = classPathResource.getInputStream();
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes);
            System.out.println(new String(bytes));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
